/**
 * 
 */
package com.dsteiner.xelavos.client.model;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.domain.ModelObject;
import com.dsteiner.xelavos.client.domain.Comment;

public class CommentsModel {
	private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
			this);

	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		propertyChangeSupport.registerPropertyChangeListener(
				propertyName, listener);
	}

	private ModelObject refObject;

	public ModelObject getRefObject() {
		return refObject;
	}

	public void setRefObject(ModelObject refObject) {
		ModelObject oldRefObject = this.refObject;
		this.refObject = refObject;
		propertyChangeSupport.firePropertyChange("refObject", oldRefObject, refObject);
	}
	private List<Comment> comments = new ArrayList<Comment>();

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		List<Comment> oldComments = this.comments;
		this.comments = comments;
		propertyChangeSupport.firePropertyChange("comments", oldComments, comments);
	}
	
	public void addComment(Comment comment){
		List<Comment> newComments = new ArrayList<Comment>();
		newComments.add(comment);
		newComments.addAll(comments);
		setComments(newComments);
	}
}